package com.bw.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bw.common.Result;
import com.bw.entity.*;
import com.bw.form.RoleQueryForm;
import com.bw.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class RoleController {


    @Autowired
    RoleService roleService;

    @RequestMapping("/getRolePage")
    public IPage<SysRole> getRolePage(Page page, RoleQueryForm query){

       return roleService.getRolePage(page,query);
    }


    /**
     * 添加角色
     *
     * @return
     */
    @RequestMapping("/addRole")
    public Result addRole(@RequestBody SysRole sysRole) {
        roleService.addRole(sysRole);
        return Result.ok("success");
    }

    /**
     * 修改角色
     *
     * @return
     */
    @RequestMapping("/updateRole")
    public Result updateRole(@RequestBody SysRole sysRole) {
        roleService.updateRole(sysRole);
        return Result.ok("success");
    }

    /**
     * 删除用户
     *
     * @return
     */
    @RequestMapping("/deleteRole/{ids}")
    public Result deleteRole(@PathVariable String ids) {
        roleService.deleteRole(ids);
        return Result.ok("success");
    }

    @RequestMapping("/getMenuByRole")
    public Result getMenuByRole(Long roleId) {
        List<UserMenu> menuList =  roleService.getMenuByRole(roleId);
        return Result.ok(menuList);
    }

    /**
     * 修改角色菜单
     *
     * @return
     */
    @RequestMapping("/saveRoleMenu")
    public Result saveRoleMenu(@RequestBody RoleMenuDto roleMenuDto) {
        roleService.saveRoleMenu(roleMenuDto);
        return Result.ok("success");
    }
}
